var mt = {
    begin: new Date()
};
//保留原始的alert
window.originalAlert = window.alert;
//startsWith的polyfill
if (!String.prototype.startsWith) {
    String.prototype.startsWith = function(searchString, position){
      position = position || 0;
      return this.substr(position, searchString.length) === searchString;
  };
}

var $EP = {
	url : '',
	dsKey : '',
	jsv : '',
	enc: '',
	pwdEncWithRSA: true,
	forceLoginAllow : false,
	verifyAuth : false,
	uid : '',
	
	getUrl : function(callback) {
		callback({
			url : this.url,
			dataService : this.dataService,
			jsv : this.jsv,
			forceLoginAllow : this.forceLoginAllow,
			verifyAuth : this.verifyAuth,
			language : this.language,
			enc : this.enc,
			pwdEncWithRSA: this.pwdEncWithRSA,
			xhrDigest: this.xhrDigest,
			quickId : this.quickId,
			uid: this.uid
		});
	},
	
	setStaff : function(staff, callback) {
		window.localStorage.setItem('staff', JSON.stringify(staff));
		callback();
	},
	
	getStaff : function() {
		if (this.staff)
			return this.staff;
		
        return JSON.parse(window.localStorage.getItem('staff'));
	},
	
	setDataService : function(dataService, callback) {
		window.localStorage.setItem('dataService', JSON.stringify(dataService));
		callback();
	},
	
	getDataService : function() {
		if (this.dataService)
			return this.dataService;
		
		return JSON.parse(window.localStorage.getItem('dataService'))
	},
	
	getDeviceUid : function(succFunc, errFunc){
		Cordova.exec(function(ret){
			if(succFunc){
				succFunc(ret);
			}
		}, function(){
			if(errFunc){
				errFunc();
			}
		}, 'ElitePlugin', 'getDeviceUid', []);
	},
	
	startChatActivity: function(succFunc, errFunc){
		Cordova.exec(function(ret){
			if(succFunc){
				succFunc(ret);
			}
		}, function(){
			if(errFunc){
				errFunc();
			}
		}, 'ElitePlugin', 'startChatActivity', []);
	},
	
	setItem: function(succFunc, errFunc, key, value){
		Cordova.exec(function(ret){
			if(succFunc){
				succFunc(ret);
			}
		}, function(){
			if(errFunc){
				errFunc();
			}
		}, 'ElitePlugin', 'setItem', [key, value]);
	},
	
	getItem: function(succFunc, errFunc, key){
		Cordova.exec(function(ret){
			if(succFunc){
				succFunc(ret);
			}
		}, function(){
			if(errFunc){
				errFunc();
			}
		}, 'ElitePlugin', 'getItem', [key]);
	},
	
	removeItem: function(succFunc, errFunc, key){
		Cordova.exec(function(ret){
			if(succFunc){
				succFunc(ret);
			}
		}, function(){
			if(errFunc){
				errFunc();
			}
		}, 'ElitePlugin', 'removeItem', [key]);
	},
}

window.onerror = function(msg, url, l){
	originalAlert("[Error] msg: " + msg + "  url: " + url + "  line: " + l);
}